import request from "@/utils/request";
import type {
  SpuValueModel,
  SpuListModel,
  SpuParamsListModel,
  SpuImageListModel,
  SpuSaleAttrListModel,
  BaseSaleAttrListModel,
} from "./model/spuModel";
/* 
    GET /admin/product/{page}/{limit}
    POST /admin/product/updateSpuInfo
    POST /admin/product/saveSpuInfo
    GET /admin/product/getSpuInfo/{spuId}
    DELETE /admin/product/deleteSpu/{spuId}
    GET /admin/product/spuImageList/{spuId}
    GET /admin/product/baseSaleAttrList
    GET /admin/product/spuSaleAttrList/{spuId}
*/
enum Api {
  SpuList = "/admin/product/",
  UpdateList = "/admin/product/updateSpuInfo",
  SaveSpu = "/admin/product/saveSpuInfo",
  GetSpuSaleAttrList = "/admin/product/spuSaleAttrList",
  GetSpuImageList = "/admin/product/spuImageList",
  GetSpuInfo = "/admin/product/getSpuById",
  GetBaseSaleAttrList = "/admin/product/baseSaleAttrList",
}
//获取分页列表数据
export const getSpuListApi = ({
  page,
  limit,
  category3Id,
}: SpuParamsListModel) => {
  return request.get<any, SpuListModel>(Api.SpuList + `/${page}/${limit}`, {
    params: {
      category3Id,
    },
  });
};

/**
 * 获取基础销售属性列表

 */
export const getBaseSaleAttrListApi = () => {
  return request.get<any, BaseSaleAttrListModel>(Api.GetBaseSaleAttrList);
};

//添加或修改数据
export const addOrUpdateSpuInfoApi = (spu: SpuValueModel) => {
  return request.post(spu.id ? Api.UpdateList : Api.SaveSpu, spu);
};

/**
 * 获取图片列表
 */
export const getSpuImageListApi = (spuId: number) => {
  return request.get<any, SpuImageListModel>(Api.GetSpuImageList + `/${spuId}`);
};

/**
 * 获取销售属性列表

 */
export const getSpuSaleAttrListApi = (spuId: number) => {
  return request.get<any, SpuSaleAttrListModel>(
    Api.GetSpuSaleAttrList + `/${spuId}`
  );
};

/**
 * 获取SPU详情

 */
export const getSpuInfoApi = (spuId: number) => {
  return request.get<any, SpuValueModel>(Api.GetSpuInfo + `/${spuId}`);
};
